package com.example.lt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.lt.mapper.BannerMapper;
import com.example.lt.pojo.entity.Banner;
import com.example.lt.service.BannerService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 小涛Tao
 * @Date: 2024/05/30/19:48
 * version 1.0 注释：
 **/
@Service
@RequiredArgsConstructor
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {

    private final BannerMapper bannerMapper;

    /**
     * 获取所有轮播图
     * @return
     */
    @Cacheable(value = "banner", key = "'list'") // 放在缓存中 redis 是以key-value进行存储的
    public List<Banner> getAllBanner() {
        System.out.println("此次获取所有轮播图没有走缓存"); // 这里用了spring cache来管理redis缓存
        List<Banner> bannerList = bannerMapper.selectList(null); // 获取所有轮播图
        return bannerList;
    }

}
